$(document).ready(function() {
	MyObjectHHH = {			
		knowType : 0,
		name :"",
		iiId : "",
		offset : 0,
		limit : 10,
	}
	
	function getlist() {
		MyObjectHHH.iiId = $("#4").val();
	}

	/*This Is Huang To Pages O(∩_∩)O*/
	MyObjectogHHH = {
		//"url" :"http://127.0.0.1/app/ins/knowList" ,
		"url" :Server + "/app/ins/knowList",
		knowType:0,
		name:"",
		iiId:$("#4").val(),
		offset : 0,
		limit : 10,
		haveuid : "",
		ishavesend : 1,
		boolean : false,
		type : "POST",
		dataType : "JSON",
		number : 1,
		AllCount : 0,
		nowp : 0,
		Callback : function(nowPage) {
			MyObjectogHHH.nowp = nowPage;
			MyObjectHHH.offset = nowPage-1;
			getlist();
			knowList(MyObjectHHH);
		}
	};

	function MyObjectogHHHofpageload() {
		$("#page").initPage((function() {
			$.ajax({
				//"url" :"http://127.0.0.1/app/ins/knowList" ,
				"url" :Server + "/app/ins/knowList",
				"type" : MyObjectogHHH.type,
				"dataType" : MyObjectogHHH.dataType,
				"async" : MyObjectogHHH.boolean,
				"data" : MyObjectHHH,
				success : function(data) {
					MyObjectogHHH.AllCount = data.count;
				}
			});
			return MyObjectogHHH.AllCount;
		})(), MyObjectogHHH.number, MyObjectogHHH.Callback);
	}
	MyObjectogHHHofpageload();
	
	$('#clickleft').click(function(){
		MyObjectHHH.knowType = $(".selected").attr("value");
		MyObjectogHHHofpageload();
	})
	$("#serch").click(function(){
		MyObjectHHH.name = $("#product").val();
		MyObjectogHHHofpageload();
	})
	downloadQue();
})
	
	function knowList(MyObjectHHH){
		$.ajax({
			//"url" :"http://127.0.0.1/app/ins/knowList" ,
			"url" :Server + "/app/ins/knowList",
			"type" : "POST",
			"dataType" : "Json",
			"data" : MyObjectHHH,
			success : function(data){
				var m = data.rows;
				var html = "";
				var item ='<tr>\
					<th>仪器知识名称</th>\
					<th>文件格式</th>\
					<th>文件大小</th>\
					<th>下载次数</th>\
					<th>上传者</th>\
				    </tr>';
				var pattern = '<tr>\
					<td><a onclick="detailupload(#7)">#name</a></td>\
					<td>#typle</td>\
					<td>#size</td>\
					<td>#number</td>\
					<td>#publicName</td>\
				</tr>';
				for (var i = 0; i < m.length; i++){
					var filename = m[i].knowFile;
					var filetype =  filename.substr(filename.lastIndexOf("."), filename.length);
					item += pattern.replace("#name", m[i].knowName)
					               .replace("#typle", filetype)
					               .replace("#size", m[i].fileSize)
					               .replace("#number", m[i].downCount)
					               .replace("#publicName", m[i].realname)
					               .replace("#7", m[i].id)
				}
				$("#iKnowList").html(item);
			}
		})
	}
function downloadQue(){
	$.ajax({
		//"url":"http://127.0.0.1/app/ins/downloadQue",
		"url" :Server + "/app/ins/downloadQue",
		"type":"POST",
		"dataType" : "Json",
		"async": false,
		success : function(data){
			var html ="";
			var item ="";
			var pattern ='<li onclick="detaildownloadQue(#3)">#1.#2</li>';
			for(var i=0;i<data.length;i++){
				var num =i+1;
				item += pattern
				        .replace("#1", num)
				        .replace("#2", data[i].knowName)
				        .replace("#3", data[i].id)
			}
			$("#queueList").html(item);
		}
	})
}

function detailupload(id){
	$(location).attr('href', 'machine13?id=' + id + '');
}
function detaildownloadQue(id){
	$(location).attr('href', 'machine13?id=' + id + '');
}

